import React, { Component } from 'react';

//类组件写法：高阶组件函数
function infoHOC(Com) {
  return class extends Component {
    state = {
      info: []
    };

    //请求数据
    componentDidMount() {
      (async () => {
        let res = await fetch(
          'https://jsonplaceholder.typicode.com/users'
        ).then((res) => res.json());

        // console.log(res);
        //[{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]

        //缓存数据
        this.setState({
          info: res
        });
      })();
    }

    render() {
      //{...this.state}展开所有属性并传入
      return <Com {...this.state}></Com>;
    }
  };
}

export default infoHOC;
